import { createStore, applyMiddleware } from 'redux'
import logger from 'redux-logger'
import reducer from './reducer'
import thunk from 'redux-thunk'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
// 生成一个持久化的纯函数
var persistedReducer = persistReducer(
    { key: 'redux', storage },
    reducer
)
// 创建一个store
// createStore(纯函数，应用插件) 创建一个唯一的store
// appliMiddleware()应用第三方插件到redux
// logger本质是函数，负责打印日志（每当store中的数据发生改变时，就会自动打印日志）
var store = createStore(persistedReducer, applyMiddleware(thunk, logger))

// 生成一个持久化的store
export var persistor = persistStore(store);
export default store